package com.tgy.controller;

import com.tgy.service.AsyncService;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/***
 * @ClassName: AsyncController
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 14:35 2022/1/7
 * @version : V1.0
 */
@Controller
public class AsyncController {
    @Resource
    AsyncService asyncService;
    @Resource
    JavaMailSenderImpl mailSender;

    @GetMapping("/aa")
    @ResponseBody
    public String async(){
        this.asyncService.async();
        return "完成";
    }
    @RequestMapping({"/","/index"})
    public String index(){
        return "index";
    }

    @GetMapping("/send")
    @ResponseBody
    public String send(@RequestParam("subject") String subject,
                       @RequestParam("text") String text,
                       @RequestParam( name ="address", required = false,defaultValue ="1053480345@qq.com") String address ){
        //邮件设置1：一个简单的邮件
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject(subject);
        message.setText(text);

        message.setTo(address);
        message.setFrom("664068464@qq.com");
        mailSender.send(message);
        return "完成";
    }
}
